package com.kiragame.couplescreen;

import java.util.HashMap;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

public class DataManager {
	private static DataManager mDataManager;
	private SharedPreferences pref;
	private SharedPreferences prefContact;
	private Editor editor;
	private Editor editorContact;
	public static final String REPOSITORY_CONTACT = "Couple_screen_contact";
	public static final String DEVICE_CONTACT_ID = "device_contact_id";
	public static final String USER_ID = "user_id";
	private static final String CURRENT_DEVICE_CONTACT_ID = "current_device_contact_id";

	public DataManager(Context context) {
		pref = PreferenceManager.getDefaultSharedPreferences(context);
		prefContact = context.getSharedPreferences(REPOSITORY_CONTACT, Context.MODE_PRIVATE);
		editor = pref.edit();
		editorContact = prefContact.edit();
	}

	public static DataManager getInstance(Context context) {
		if (mDataManager == null) {
			mDataManager = new DataManager(context);
		}
		return mDataManager;
	}
	
	public void setCurrentContactID(String id){
		editor.putString(CURRENT_DEVICE_CONTACT_ID, id);
		editor.commit();
	}
	
	public String getCurrentContactID(){
		return pref.getString(CURRENT_DEVICE_CONTACT_ID, null);
	}
	
	public void setDeviceContactID(String id){
		editor.putString(DEVICE_CONTACT_ID, id);
		editor.commit();
	}
	
	public String getDeviceContactID(){
		return pref.getString(DEVICE_CONTACT_ID, null);
	}
	
	public void setUserID(int id){
		editor.putInt(USER_ID, id);
		editor.commit();
	}
	
	public int getUserID(){
		return pref.getInt(USER_ID, 0);
	}
	
	public void saveContact(String name, String id){
		editorContact.putString(name, id);
		editorContact.commit();
	}
	
	public void removeContact(String name){
		editorContact.remove(name);
		editorContact.commit();
	}
	
	@SuppressWarnings("unchecked")
	public HashMap<String, String> getAllContact(){
		return (HashMap<String, String>) prefContact.getAll();
	}
}
